package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.dao.SetmealDao;
import com.itheima.untils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.*;

/* reportDate:null,
   todayNewMember :0,
   totalMember :0,
   thisWeekNewMember :0,
   thisMonthNewMember :0,
   todayOrderNumber :0,
   todayVisitsNumber :0,
   thisWeekOrderNumber :0,
   thisWeekVisitsNumber :0,
   thisMonthOrderNumber :0,
   thisMonthVisitsNumber :0,
   hotSetmeal :[
       {name:'阳光爸妈升级肿瘤12项筛查（男女单人）体检套餐',setmeal_count:200,proportion:0.222},
       {name:'阳光爸妈升级肿瘤12项筛查体检套餐',setmeal_count:200,proportion:0.222}*/
@Service
public class ReportServiceimpl implements ReportService {
    @Autowired
    MemberDao memberDao;
    @Autowired
    OrderDao orderDao;
    @Autowired
    SetmealDao setmealDao;
    @Override
    public Map<String, Object> getBusinessReportData() throws Exception {
        String firstDay4ThisMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        String thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        String sundayOfThisWeek = DateUtils.parseDate2String(DateUtils.getSundayOfThisWeek());
        String today = DateUtils.parseDate2String(DateUtils.getToday());
        String LastDay4ThisMonth = DateUtils.parseDate2String(DateUtils.getLastDay4ThisMonth());
        Long todayNewMember= memberDao.findBytodayNewMember(today);
        Long totalMember=memberDao.findBytotalMember();
        Long thisWeekNewMember= memberDao.findNewMember(thisWeekMonday);
        Long thisMonthNewMember=memberDao.findNewMember(firstDay4ThisMonth);
        Long todayOrderNumber= orderDao.findtodayOrderNumber(today);
        Long todayVisitsNumber=orderDao.findtodayVisitsNumber(today);
        Long thisWeekOrderNumber=orderDao.findOrderNumber(thisWeekMonday,sundayOfThisWeek);
        Long thisWeekVisitsNumber= orderDao.findVisitsNumber(thisWeekMonday);
        Long thisMonthOrderNumber=orderDao.findOrderNumber(firstDay4ThisMonth,LastDay4ThisMonth);
        Long thisMonthVisitsNumber=orderDao.findVisitsNumber(firstDay4ThisMonth);
        List<Map<String,Object>> mapList=setmealDao.findSetmeal();
        Map<String,Object> map=new HashMap<>();
        map.put("reportDate",today);
        map.put("todayNewMember",todayNewMember);
        map.put("totalMember",totalMember);
        map.put("thisWeekNewMember",thisWeekNewMember);
        map.put("thisMonthNewMember",thisMonthNewMember);
        map.put("todayOrderNumber",todayOrderNumber);
        map.put("todayVisitsNumber",todayVisitsNumber);
        map.put("thisWeekOrderNumber",thisWeekOrderNumber);
        map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        map.put("thisMonthOrderNumber",thisMonthOrderNumber);
        map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        map.put("hotSetmeal",mapList);
        return map;
    }
}
